package database

import (
	openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
	rds20140815 "github.com/alibabacloud-go/rds-20140815/v3/client"
	util "github.com/alibabacloud-go/tea-utils/v2/service"
	"github.com/alibabacloud-go/tea/tea"
)

type RDSGreeter interface {
	RDS(region string) RDSInterface
}

type RDSInterface interface {
}

type rds struct {
	region string
	config *openapi.Config
	client *rds20140815.Client
}

func newRDS(db *Database, region string) RDSInterface {
	c := &rds{
		region: region,
		config: db.config,
	}
	c.config.Endpoint = tea.String(string(RDSEndPoint))
	_client, _ := rds20140815.NewClient(c.config)
	c.client = _client
	return c
}

func (d *rds) CreateMySQLPostPaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) CreateMySQLPrepaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) CreateSqlServerPostPaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) CreateSqlServerPrepaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) CreatePostgreSQLPostPaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) CreatePostgreSQLPrepaidInstance() (instanceId string, err error) {
	return
}

func (d *rds) createInstance(payType string, engine string) {
	createDBInstanceRequest := &rds20140815.CreateDBInstanceRequest{
		RegionId:              tea.String(d.region),
		EngineVersion:         tea.String("5.7"),
		Engine:                tea.String("MySQL"), // MySQL, SQLServer, PostgreSQL
		DBInstanceClass:       tea.String("mysql.n2.serverless.1c"),
		DBInstanceStorage:     tea.Int32(100),
		DBInstanceNetType:     tea.String("Intranet"),
		DBInstanceDescription: tea.String("description"),
		SecurityIPList:        tea.String("0.0.0.0/0"),
		PayType:               tea.String("Postpaid"), // Postpaid, Prepaid
		InstanceNetworkType:   tea.String("VPC"),
		VPCId:                 tea.String("vpcid"),
		VSwitchId:             tea.String("subnetid"),
		UsedTime:              tea.String("1"),
		Period:                tea.String("Month"),
		DBInstanceStorageType: tea.String("cloud_essd"),
		AutoRenew:             tea.String("true"),
		Category:              tea.String("Basic"),
		Amount:                tea.Int32(1),
		DBIsIgnoreCase:        tea.String("true"),
		ConnectionMode:        tea.String("Standard"),
		ZoneId:                tea.String("cn-shanghai-b"),
		Port:                  tea.String("3306"),
	}
	runtime := &util.RuntimeOptions{
		ReadTimeout:    tea.Int(50000),
		ConnectTimeout: tea.Int(50000),
	}
	_, _ = d.client.CreateDBInstanceWithOptions(createDBInstanceRequest, runtime)
}
